package designPattern.visitorPattern.visitor;

/**
 * DiscountVisitor
 *
 * @author nanxin.chen
 * @date 2015/8/29
 */
public class VisitorDiscount implements IShoppingVisitor {
    private double bookDiscount = 0.8;
    private double fruitDiscount = 0.9;

    @Override
    public double visit(Fruit fruit) {
        String info =  String.format("name:%s, num:%s, price:%s, discount:%s, total:", fruit.getName(), fruit.getNum(), fruit.getPrice(),fruitDiscount);
        System.out.println(info + fruit.getPrice() * fruit.getNum() * fruitDiscount);
        return fruit.getPrice() * fruit.getNum() * fruitDiscount;
    }
    @Override
    public double visit(Book book) {
        String info =  String.format("name:%s, num:%s, price:%s, ISBN:%s, discount:%s, total:", book.getName(), book.getNum(), book.getPrice(), book.getISBN(),bookDiscount);
        System.out.println(info + book.getPrice() * book.getNum() * bookDiscount);
        return book.getPrice() * book.getNum() * bookDiscount;
    }
}
